
// 计算日期是一年中第几天
export const getDate = (date) => {
  let currentYear = date.getFullYear(); // 获取当前年
  let currentMonth = date.getMonth() + 1; // 获取当前月
  let currentDate = date.getDate();
  let getMonth=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30);
  let sum1=0, i, sum;
  for(i=0;i<currentMonth-1;i++) {
    sum1+=getMonth[i]
  }
  if(( currentYear % 400 == 0||( currentYear % 4 == 0&& currentYear % 100 != 0))&& currentMonth > 2) {
    sum = sum1 + currentDate +1;
    return sum;
  }else{
    sum=sum1+currentDate;
    return sum;
  }
}

export const changeDate = (date, format) => {
  //format为需要传出的格式，格式为1则为正常时间输出，为2则是 时:分 格式
  let Year = date.getFullYear(); // 获取年
  let Month = date.getMonth() + 1; // 获取月
  let getDate = date.getDate(); // 获取日
  let hour = date.getHours(); //获取时
  if( hour < "10") {
    hour = "0" + hour;
  }
  let minutes = date.getMinutes(); //分
  if( minutes < "10") {
    minutes = "0" + minutes;
  }
  let seconds = date.getSeconds(); //秒
  if(format == 2) {
    return hour + ':' + minutes;
  }
  return Year + '-' + Month + '-' + getDate + ' ' + hour + ':' + minutes + ':' + seconds;
}
